package com.haobangs.imms.service.impl;

import java.util.Arrays;
import java.util.List;
import com.ruoyi.common.config.MyLambdaQueryWrapper;
import com.ruoyi.common.config.MyLambdaQueryWrapper;
import com.ruoyi.common.utils.DateUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.haobangs.imms.mapper.WorkshopMapper;
import com.haobangs.imms.domain.Workshop;
import com.haobangs.imms.service.IWorkshopService;

/**
 * 车间管理Service业务层处理
 *
 * @author ruoyi
 * @date 2023-06-12
 */
@Service
public class WorkshopServiceImpl implements IWorkshopService
{
    @Autowired
    private WorkshopMapper workshopMapper;

    /**
     * 查询车间管理
     *
     * @param id 车间管理主键
     * @return 车间管理
     */
    @Override
    public Workshop selectWorkshopById(Long id)
    {
        return workshopMapper.selectById(id);
    }

    /**
     * 分页查询车间管理
     *
     * @param workshop 车间管理
     * @return Page 对象
     */
    public Page getByPage(Workshop workshop){
        MyLambdaQueryWrapper<Workshop> wrapper = new MyLambdaQueryWrapper<>();
                    wrapper.likeIfPresent(Workshop::getWorkshopName, workshop.getWorkshopName());
                    wrapper.eqIfPresent(Workshop::getFactoryId, workshop.getFactoryId());
        Page<Workshop> workshops = workshopMapper.selectPage(new Page<>(workshop.getPageNum(), workshop.getPageSize()), wrapper);
        return workshops;
    }

    /**
     * 查询车间管理列表
     *
     * @param workshop 车间管理
     * @return 车间管理
     */
    @Override
    public List<Workshop> selectWorkshopList(Workshop workshop)
    {
        MyLambdaQueryWrapper<Workshop> wrapper = new MyLambdaQueryWrapper<>();
                    wrapper.likeIfPresent(Workshop::getWorkshopName, workshop.getWorkshopName());
                    wrapper.eqIfPresent(Workshop::getFactoryId, workshop.getFactoryId());
        return workshopMapper.selectList(wrapper);
    }

    /**
     * 新增车间管理
     *
     * @param workshop 车间管理
     * @return 结果
     */
    @Override
    public int insertWorkshop(Workshop workshop)
    {
        workshop.setCreateTime(DateUtils.getNowDate());
        return workshopMapper.insert(workshop);
    }

    /**
     * 修改车间管理
     *
     * @param workshop 车间管理
     * @return 结果
     */
    @Override
    public int updateWorkshop(Workshop workshop)
    {
        workshop.setUpdateTime(DateUtils.getNowDate());
        return workshopMapper.updateById(workshop);
    }

    /**
     * 批量删除车间管理
     *
     * @param ids 需要删除的车间管理主键
     * @return 结果
     */
    @Override
    public int deleteWorkshopByIds(Long[] ids)
    {
        if(ids.length == 0){
            throw new RuntimeException("id不能为空");
        }
        return workshopMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除车间管理信息
     *
     * @param id 车间管理主键
     * @return 结果
     */
    @Override
    public int deleteWorkshopById(Long id)
    {
        return workshopMapper.deleteById(id);
    }
}
